﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Emailing;
using Volo.Abp.EventBus;
using XfTech.SmartTms.Events;

namespace XfTech.SmartTms.EventHandlers
{
    /// <summary>
    /// 订阅车辆添加事件
    /// </summary>
    public class VehicleAddedEventHandler
          : ILocalEventHandler<VehicleAddedEvent>,
          ITransientDependency
    {
        private readonly IEmailSender _emailSender;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="emailSender"></param>
        public VehicleAddedEventHandler(IEmailSender emailSender)
        {
            _emailSender = emailSender;
        }


        /// <summary>
        /// 处理车辆添加事件
        /// </summary>
        /// <param name="eventData"></param>
        /// <returns></returns>
        public async Task HandleEventAsync(VehicleAddedEvent eventData)
        {
            string emailContent = $"车辆已添加：{eventData.VehicleId} + {eventData.LicensePlate} + {eventData.Company}";
            //真正去发送邮件
            await _emailSender.SendAsync(
                "99825949@qq.com",     // target email address
                "添加新车辆",         // subject
                emailContent  // email body
            );

        }
    }
}
